<template>
    <div class="feeStandard">
        <div class="main">
            <div class="tmpHeader">
                <span
                    v-for="(item,index) in tabList"
                    :key="item.value"
                    :class="{active:type == item.value }"
                    @click="changeType(item.value)"
                    
                >{{ item.title }}</span>
            </div>
            <h1 class="hospitalName">{{ hospitalName }}</h1>
            <div class="margin-up-down">
                <!-- 单项项目添加 -->
                <Button type="info"  @click='modalShow' v-if="type == 1 "  style="width:51px;height:35px;">
                    <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                </Button>    
                <!-- 添加组合项 -->
                <Button type="info" v-if="type == 2  "  @click='modalShowZH' style="width:51px;height:35px;">
                    <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                </Button>
                <!-- 添加套餐 -->
                <Button type="info" v-if="type ==3"  @click='modalShowTC' style="width:51px;height:35px;">
                    <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                </Button>
            </div>     
            <div class="margin-up-down" v-if="type == 1 ">
                <Select class="w-select" clearable v-model="inqConType" style="width:120px;" placeholder="项目类别">
                    <Option
                        v-for="item in projectlist"
                        :value="item.dictValue"
                        :key="item.dictValue"
                        style='text-align:center'
                    >{{item.dictName}}</Option>
                </Select>
            </div>
            <div class="margin-up-down">
                <Input
                v-model.trim="Name"
                placeholder="请输入项目名称检索"
                style="width: 150px"
                clearable
                />
            </div>
            <div class="margin-up-down">
                <Button style="width:51px;height:35px;" type="primary" icon="ios-search" v-if="type == 1 " @click="getDate(1)"></Button>
                <Button style="width:51px;height:35px;" type="primary" icon="ios-search" v-if="type == 2 " @click="combination(1,1)"></Button>
                <Button style="width:51px;height:35px;" type="primary" icon="ios-search" v-if="type == 3 " @click="combination(2,1)"></Button>
            </div>
            <Table stripe :columns="columns" :data="data" style="width:100%;"></Table>
            <div class="page">
                <Page :total="count" :current='pageNo' :pageSize="pageSize" show-total show-elevator @on-change="pageChange"/>
            </div>
        </div>
    </div>
</template>
<script>
import api from "@/api/commonApi";
import aesUtils from "@/plugins/aes-utils.js";
import store from "@/store";
export default {
    data () {
        const that = this;
        return {
            chargingUnitList:[],
            // tab列表
            tabList: [
                {
                    title: "单项项目",
                    value: 1
                },
                {
                    title: "组合项目",
                    value: 2
                },
                {
                    title: "套餐项目",
                    value: 3
                },
                
            ],
            hospitalName: "",
            type: 1,
            projectlist:[
                {dictName: '全部', dictValue: 0},            
                {dictName: '健康咨询', dictValue: 1},            
                {dictName: '巡诊', dictValue: 2},            
                {dictName: '检查项目', dictValue: 3},            
                {dictName: '检验项目', dictValue: 4},            
                {dictName: '治疗项目', dictValue: 5},  
                {dictName: '手术项目', dictValue: 6},  
                {dictName: '体检项目', dictValue: 7},  
                {dictName: '其他', dictValue: 8},  
            ],
            projectStatus: null,
            Name: "",
            inqConType:'',
            isDisable: false,//表单重复提交
            // 列表数据
            columns: '',
            data: [],
            data1: [],
            columns1: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80,
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    key: "itemName",
                    title: "收费项目名称",
                    align: "center"
                },
                {
                    key: "itemType",
                    title: "项目类别",
                    align: "center"
                },
                {
                    key: "itemCode",
                    title: "物价编码",
                    align: "center"
                },
                {
                    key: "itemSpec",
                    title: "项目规格",
                    align: "center"
                },
                {
                    key: "itemFeeUnitName",
                    title: "单位",
                    align: "center",
                    render: (h, params) => {
                        this.chargingUnitList.forEach(i => {
                            if(i.id == params.row.itemFeeUnit){
                                params.row.itemFeeUnitName = i.name
                            }
                        })
                        return params.row.itemFeeUnitName;
                    }
                },
                {
                    key: "itemFeePrice",
                    title: "单价(元)",
                    align: "center",
                },
                {
                    key: "hisTechnologyCode",
                    title: "HIS编码",
                    align: "center",
                  
                },
                {
                    key: "hisTechnologyName",
                    title: "HIS名称",
                    align: "center",
                  
                },
                {
                    key: "itemUsed",
                    title: "状态",
                    align: "center",
                  
                },
                {
                    title: "设置",
                    align: "center",
                    width:100,
                    render:(h,params) => {
                        let row = params.row;
                        return [
                            h('span', {
                                style: {
                                    color: " #5362e1",
                                    width: "60px"
                                },
                                on: {
                                    click: () => {
                                        this.edit(row);
                                        this.isDisable = false
                                        this.modalStatus = true
                                        this.buttonName = '确认修改'
                                        this.ModalTitle = '修改'
                                        
                                    }
                                }
                            }, '编辑')
                        ]
                    }
                }
            ],
            data2: [],
            columns2: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80,
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    key: "classifyName",
                    title: "项目分类",
                    align: "center"
                },
                {
                    key: "techName",
                    title: "项目名称",
                    align: "center"
                },
                {
                    key: "executiveDeptName",
                    title: "执行科室",
                    align: "center"
                },
                {
                    key: "chargingUnit",
                    title: "单位",
                    align: "center",
                    render: (h, params) => {
                        this.chargingUnitList.forEach(i => {
                            if(i.id == params.row.chargingUnit){
                                params.row.chargingUnitName = i.name
                            }
                        })
                        return params.row.chargingUnitName;
                    }
                },
                {
                    key: "chargingPrice",
                    title: "单价（元）",
                    align: "center",
                  
                },
                {
                    key: "positionName",
                    title: "检查部位/标本类型",
                    align: "center",
                },
                {
                    key: "isubscribe",
                    title: "是否预约项",
                    align: "center",
                  
                },
                {
                    key: "ienable",
                    title: "状态",
                    align: "center",
                  
                },
                {
                    title: "设置",
                    align: "center",
                    width:100,
                    render:(h,params) => {
                        let row = params.row;
                        return [
                            h('span', {
                                style: {
                                    color: " #5362e1",
                                    width: "60px"
                                },
                                on: {
                                    click: () => {
                                        this.edit(row);
                                        this.isDisable = false
                                        this.modalStatus = true
                                        this.buttonName = '确认修改'
                                        this.ModalTitle = '修改'
                                        
                                    }
                                }
                            }, '编辑')
                        ]
                    }
                }
            ],
            data3: [],
            columns3: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80,
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    key: "inspection",
                    title: "项目分类",
                    align: "center"
                },
                {
                    key: "techName",
                    title: "项目名称",
                    align: "center"
                },
                {
                    key: "executiveDeptName",
                    title: "执行科室",
                    align: "center"
                },
                {
                    key: "chargingUnit",
                    title: "单位",
                    align: "center",
                    render: (h, params) => {
                        this.chargingUnitList.forEach(i => {
                            if(i.id == params.row.chargingUnit){
                                params.row.chargingUnitName = i.name
                            }
                        })
                        return params.row.chargingUnitName;
                    }
                },
                {
                    key: "chargingPrice",
                    title: "单价（元）",
                    align: "center",
                  
                },
                {
                    key: "isubscribe",
                    title: "是否预约项",
                    align: "center",
                  
                },
                {
                    key: "ienable",
                    title: "状态",
                    align: "center",
                  
                },
                {
                    title: "设置",
                    align: "center",
                    width:100,
                    render:(h,params) => {
                        let row = params.row;
                        return [
                            h('span', {
                                style: {
                                    color: " #5362e1",
                                    width: "60px"
                                },
                                on: {
                                    click: () => {
                                        this.edit(row);
                                        this.isDisable = false
                                        this.modalStatus = true
                                        this.buttonName = '确认修改'
                                        this.ModalTitle = '修改'
                                        
                                    }
                                }
                            }, '编辑')
                        ]
                    }
                }
            ],
            columns4: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80,
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    key: "sum",
                    title: "HIS项目编码",
                    align: "center",
                    width:80
                },
                {
                    key: "sum",
                    title: "HIS项目名称",
                    align: "center",
                    width:80
                },
                {
                    key: "sum",
                    title: "计量单位",
                    align: "center",
                    width:80
                },
                {
                    key: "sum",
                    title: "单价（元）",
                    align: "center",
                    width:80
                },
                {
                    key: "sum",
                    title: "关联数量",
                    align: "center",
                    width:80
                },
                {
                    key: "sum",
                    title: "设置",
                    align: "center",
                    width:80
                },
            ],
            // 分页数据
            count: 10,
            pageNo: 1,
            pageSize: 10,
            // 弹出窗状态
            modalStatus: false,
            ModalTitle : "新增",         
            // 项目类型列表
            projectCategoryList: [
                {
                    name:"健康咨询",
                    id:'1'
                },
                {
                    name:"巡诊",
                    id:'2'
                },
                {
                    name:"检查项目",
                    id:'3'
                },
                {
                    name:"检验项目",
                    id:'4'
                },
                {
                    name:"治疗项目",
                    id:'5'
                },
                {
                    name:"手术项目",
                    id:'6'
                },
                {
                    name:"体检项目",
                    id:'7'
                },
                {
                    name:"其他",
                    id:'8'
                },
            ],
            //标本类列表
            specimenList: [],
            // 业务模块
            modular: [],
            Allmodular: ["健康咨询","问诊","复诊","续方","用药咨询"],
            // 咨询列表
            consultList: [
                { name: "健康咨询", id: 0 },
                { name: "用药咨询", id: 4 }
            ],
            // 问诊列表
            inquiryList: [
                { name: "问诊", id: 1 },
                { name: "复诊续方", id: 2 },
                // {
                //     name: "续方",
                //     id: 3
                // },
                
            ],
            consultationFormList: [
                {id: 0, name: '图文'},
                {id: 1, name: '电话/语音'},
                {id: 2, name: '视频'}
            ],
            buttonName: "确认添加",
            // 咨询类型
            consultTypeList: [
                {
                    id:"1",
                    name:"图文咨询"
                },
                {
                    id:"2",
                    name:"视频咨询"
                },
                {
                    id:"3",
                    name:"语音咨询"
                }
            ],
            tableLoading: false,
            hospitalId: sessionStorage.getItem("hospitalId"),
        };
    },
    created () {
        if(this.$store.state.resourceUrl == 'gphealth'){
            this.projectlist = this.projectlist.filter(col => col.dictName !== '巡诊');
        }
        let pageNo = this.$route.query.pageNo
            ? parseInt(this.$route.query.pageNo)
            : 1;
            if (pageNo) {
            this.pageNo = pageNo;
        }
        this.type = this.$route.query.type
        ? this.$route.query.type
        : '1';
        if(this.type == 1){
            this.getDate(this.pageNo)
            this.columns = this.columns1
        }
        if(this.type == 2){
            this.combination(1,1)
            this.columns = this.columns2
        } 
        if(this.type == 3){
            this.combination(2,1)
            this.columns = this.columns3
        } 
        let breadList = [
            { path: "/index", title: "首页" },
            {
                path: "/index/operation/mechanism/index",
                title: "机构运营"
            },
            {
                path: "/index/operation/home",
                title: "机构配置管理"
            }
        ];
        this.$emit("changeBreadList", breadList);
    },
    mounted () {
        let iv = store.state.iv;
        let salt = store.state.salt;
        let storage = localStorage.getItem("hospitalName")
        if(Boolean(storage)) {
            this.hospitalName = aesUtils.decrypt(
            salt,
            iv,
            "Doctortoservice",
            storage
            )
        }
        let pageNo = this.$route.query.pageNo;
        this.hospitalId = this.$route.query.hospitalId;
        if (pageNo) {
            this.pageNo = pageNo;
        }
        this.getfeeunitenum()
    },
    methods: {
        // 加载收费列表
         getfeeunitenum(){
              this.$axios.post(api.findFeeEnum,{}).then(resp => {
                if(resp.data.success) {
                    let ret = resp.data;
                    this.chargingUnitList = ret.object;
                }
            })
         },
        // 根据tabs状态的不同加载不同的数据
        changeType(val){
            this.type = val
            this.Name = ''
            if(this.type == 1){
                this.getDate(this.pageNo)
                this.columns = this.columns1
            }
            if(this.type == 2){
                this.combination(1,1)
                this.columns = this.columns2
            } 
            if(this.type == 3){
                this.combination(2,1)
                this.columns = this.columns3
            } 
        },
        // 分页器改变
        pageChange(index) {
            this.pageNo = index;
            if (this.Name) {
                if(this.type == '1'){
                    this.getDate(index, this.Name);
                } else if (this.type == '2'){
                    this.combination(1,index, this.Name);
                } else {                  
                    this.combination(2,index, this.Name);
                }               
            } else {
                if(this.type == '1'){
                    this.getDate(index);
                } else if (this.type == '2'){
                    this.combination(1,index);
                } else {
                    this.combination(2,index);
                }           
            }
        },
        //表格
        selectChange(selections) {
            this.selections = selections;
        },
        //返回单项主页面
        handleReset(){
            this.pageNo = 1
            this.type = '1'
            this.columns = this.columns1
            this.functionJS.queryNavgationTo(
                this,
                "/index/directory/priceManagement/index",
            );
            this.Name = ''
            this.getDate(this.pageNo)
        },
        // 新增项目
        modalShow () {
            this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/add", {
                pageNo: this.pageNo,
                hospitalId:this.hospitalId,
                isBack: 2
            });
        }, 
        modalShowZH(){
            this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/addZH", {
                pageNo: this.pageNo,
                hospitalId:this.hospitalId,
                isBack: 2
            });
        },  
        modalShowTC(){
            this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/addTC", {
                pageNo: this.pageNo,
                hospitalId:this.hospitalId,
                isBack: 2
            });
        },
        //获取组合项管理getfeeunitenum列表
        combination(val,pageNo){
            this.count = ''
            if  (pageNo) {
                this.pageNo = Number(pageNo);
            }
            if(val == 1){
                this.type = '2'
                this.columns = this.columns2
            } else {
                this.type = '3'
                this.columns = this.columns3
            }     
            this.isDisable = false
            let params = {
                "hospitalId": this.hospitalId,
                "combinationType": val,
                "pageNo": this.pageNo,
                "pageSize": this.pageSize,
            }
            if (this.Name != "") {
                params.techName = this.Name.trim();
            }
            let url = api.findTechnologyPage
            this.$axios.post(url, params).then(res => {
                if (res.data.success) {    
                    if(res.data.object.records){
                        let ret = res.data.object;
                        this.count = ret.total
                        if(ret.records){
                            ret.records.forEach((item,index) => {
                                // 排序
                                item.sum = this.addZeros(index)
                                // 项目类型
                                this.projectCategoryList.forEach(i => {
                                    if(Number(item.inspection) == Number(i.id)) {
                                        item.inspection = i.name
                                    }
                                })
                                item.ienable = item.ienable == 1 ? "启用" : "禁用"
                                item.isubscribe = item.isubscribe == 1 ? "是" : "否"
                            })
                            this.data2 = ret.records;
                            this.data = this.data2
                        } else {
                            this.data = [];
                            this.count = 0
                        }
                    }   else {
                        this.data = [];
                        this.count = 0
                        this.$Message.info("查询结果为空");
                    }                
                    
                }
            })            
        }, 
        // 加载单项列表数据
        getDate (pageNo) {
            if  (pageNo) {
                this.pageNo = Number(pageNo);
            }
            this.isDisable = false
            let params = {
                "hospitalId": this.$route.query.hospitalId ? this.$route.query.hospitalId : this.hospitalId ,
                "pageNo": this.pageNo,
                "pageSize": this.pageSize
            }
            if (this.Name != "") {
                params.itemName = this.Name.trim();
            }
            if (this.inqConType != "") {
                params.itemType = this.inqConType;
            }
            let url = api.findChargePage
            this.$axios.post(url, params).then(res => {
                if (res.data.success) {       
                    if (res.data.object.records){
                        let ret = res.data.object;
                        this.count = ret.total
                        if(ret.records){
                            ret.records.forEach((item,index) => {
                            // 排序
                                item.sum = this.addZeros(index)
                                // 项目类型
                                this.projectCategoryList.forEach(i => {
                                    if(Number(item.itemType) == Number(i.id)) {
                                        item.itemType = i.name
                                    }
                                })
                                item.itemUsed = item.itemUsed == 1 ? "启用" : "禁用"
                            })
                            this.data1 = ret.records;
                            this.data = this.data1
                        } else {
                            this.data = [];
                            this.count = 0
                        }                       
                    }  else {
                        this.data = [];
                        this.count = 0
                        this.$Message.info("查询结果为空");
                    }         
                    
                }
            })            
        },
        // 编辑项目
        edit(item) {
            let id = item.id;
            if(this.type =='1'){
                this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/edit", {
                id,
                hospitalId:item.hospitalId,
                isBack: 2
                });
            }
            if(this.type =='2'){
                this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/editZH", {
                id,
                hospitalId:item.hospitalId,
                isBack: 2
                });
            }
            if(this.type =='3'){
                this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/editTC", {
                id,
                hospitalId:item.hospitalId,
                isBack: 2
                });
            }
        },
    },
    watch: {
        'pageSize'(nv, ov) {
            this.getDate(this.pageNo)
            this.combination(this.pageNo)
        },
    }
};
</script>
<style lang="less" scoped>
.feeStandard {
    width: calc(100%);
    padding: 10px 30px;
    margin: 0 auto;
    background: #fff;
    .hospitalName {
        width: 100%;
        text-align: center;
        height: 50px;
        line-height: 40px;
        margin-top: 15px;
    }
    .tmpHeader {
        width: 100%;
        height: 40px;
        border-bottom: 2px solid #f2f2f2;
        span {
            display: inline-block;
            line-height: 38px;
            padding: 0 15px;
            cursor: pointer;
            border-bottom: 2px solid transparent;
            transition: all 0.5s;
        }
        span.active {
            color: #5362e1;
            border-bottom: 2px solid #5362e1;
        }
        span:hover {
            border-bottom: 2px solid #5362e1;
            color: #5362e1;
        }
    }
    .main {
        // display: flex;
        // flex-direction: column;
        .margin-up-down {
            display: inline-block;
            margin: 10px 10px 10px 0px;
        }
        .page{
            text-align: center;
            margin: 20px 0;
        }
        .iheader {
            width: 100%;
            margin: 10px auto;
            display: flex;
            flex-direction: row;
            justify-content: flex-end;
        }
    }
}
</style>
